using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using HengTong.Model.Db.SupplyChain.Material;
using TiaoTaoHelper.Wtm.Models;
using WalkingTec.Mvvm.Core;

namespace HengTong.Model.Db.SupplyChain.Purchase;

/// <summary>
/// 采购需求池明细表
/// </summary>
/// <remarks>
/// 记录需求池中的具体采购需求明细，从已审批的采购申请单中汇总而来
/// </remarks>
[Display(Name = "采购需求池明细", Description = "记录需求池中的具体采购需求明细", GroupName = "供应链")]
public class SysPurchaseRequirementPoolEntry : BasePoco
{
    #region 关联信息

    /// <summary>
    /// 获取或设置需求池
    /// </summary>
    /// <value>关联的需求池主表实体</value>
    [Display(Name = "需求池", Description = "关联的需求池主表", GroupName = "关联信息")]
    public SysPurchaseRequirementPool Pool { get; set; }

    /// <summary>
    /// 获取或设置需求池ID
    /// </summary>
    /// <value>关联的需求池主表ID</value>
    [Display(Name = "需求池ID", Description = "关联的需求池主表ID", GroupName = "关联信息")]
    public Guid? PoolId { get; set; }

    /// <summary>
    /// 获取或设置采购申请单
    /// </summary>
    /// <value>关联的采购申请单主表实体</value>
    [Display(Name = "采购申请单", Description = "关联的采购申请单主表", GroupName = "关联信息")]
    public SysPurchaseRequestBill RequestBill { get; set; }

    /// <summary>
    /// 获取或设置采购申请单ID
    /// </summary>
    /// <value>关联的采购申请单主表ID</value>
    [Display(Name = "申请单ID", Description = "关联的采购申请单主表ID", GroupName = "关联信息")]
    public Guid? RequestBillId { get; set; }

    /// <summary>
    /// 获取或设置申请单明细
    /// </summary>
    /// <value>关联的采购申请单明细表实体</value>
    [Display(Name = "申请单明细", Description = "关联的采购申请单明细表", GroupName = "关联信息")]
    public SysPurchaseRequestBillEntry RequestBillEntry { get; set; }

    /// <summary>
    /// 获取或设置申请单明细ID
    /// </summary>
    /// <value>关联的采购申请单明细表ID</value>
    [Display(Name = "申请单明细ID", Description = "关联的采购申请单明细表ID", GroupName = "关联信息")]
    public Guid? RequestBillEntryId { get; set; }

    #endregion

    #region 物料信息

    /// <summary>
    /// 获取或设置物料
    /// </summary>
    /// <value>采购的物料实体信息</value>
    [Display(Name = "物料", Description = "采购的物料", GroupName = "物料信息")]
    public SysMaterial Material { get; set; }

    /// <summary>
    /// 获取或设置物料ID
    /// </summary>
    /// <value>采购的物料ID</value>
    [Required(ErrorMessage = "物料ID不能为空")]
    [Display(Name = "物料ID", Description = "采购的物料ID", GroupName = "物料信息")]
    public Guid? MaterialId { get; set; }


    public SysMaterialSku MaterialSku { get; set; }
    
    public Guid? MaterialSkuId { get; set; }

    #endregion

    #region 数量和金额

    /// <summary>
    /// 获取或设置申请数量
    /// </summary>
    /// <value>物料的申请采购数量，精度为6位小数</value>
    [Required(ErrorMessage = "申请数量不能为空")]
    [Display(Name = "申请数量", Description = "物料的申请采购数量", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal? RequestQuantity { get; set; }

    /// <summary>
    /// 获取或设置预计单价
    /// </summary>
    /// <value>预计采购单价，精度为6位小数</value>
    [Display(Name = "预计单价", Description = "预计采购单价", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal? EstimatedPrice { get; set; }

    /// <summary>
    /// 获取或设置预算金额
    /// </summary>
    /// <value>预算金额（申请数量×预计单价），精度为2位小数</value>
    [Display(Name = "预算金额", Description = "预算金额（申请数量×预计单价）", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,2)")]
    public decimal? BudgetAmount { get; set; }

    /// <summary>
    /// 获取或设置已采购数量
    /// </summary>
    /// <value>已下达采购订单的数量，精度为6位小数</value>
    [Display(Name = "已采购数量", Description = "已下达采购订单的数量", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal? PurchasedQuantity { get; set; }

    /// <summary>
    /// 获取或设置剩余数量
    /// </summary>
    /// <value>剩余待采购数量（申请数量-已采购数量），精度为6位小数</value>
    [Required(ErrorMessage = "剩余数量不能为空")]
    [Display(Name = "剩余数量", Description = "剩余待采购数量（申请数量-已采购数量）", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal? RemainingQuantity { get; set; }

    #endregion

    #region 申请信息

    /// <summary>
    /// 获取或设置申请部门
    /// </summary>
    /// <value>申请采购的部门实体</value>
    [Display(Name = "申请部门", Description = "申请采购的部门", GroupName = "申请信息")]
    public SysGroup Group { get; set; }

    /// <summary>
    /// 获取或设置申请部门ID
    /// </summary>
    /// <value>申请采购的部门ID</value>
    [Display(Name = "申请部门ID", Description = "申请采购的部门ID", GroupName = "申请信息")]
    public Guid? GroupId { get; set; }

    /// <summary>
    /// 获取或设置申请人ID
    /// </summary>
    /// <value>申请人ID</value>
    [Required(ErrorMessage = "申请人不能为空")]
    [StringLength(128)]
    [Display(Name = "申请人", Description = "申请人", GroupName = "申请信息")]
    public string RequestBy { get; set; }
    #endregion

    #region 采购类型

    /// <summary>
    /// 获取或设置采购类型
    /// </summary>
    /// <value>采购类型：常规、设备新增、安全新增等</value>
    [Required(ErrorMessage = "采购类型不能为空")]
    [Display(Name = "采购类型", Description = "采购类型：常规、设备新增、安全新增等", GroupName = "采购类型")]
    public PurchaseType? PurchaseType { get; set; }

    /// <summary>
    /// 获取或设置物料类型
    /// </summary>
    /// <value>物料类型：备品备件、化工小料、大宗原材料</value>
    [Required(ErrorMessage = "物料类型不能为空")]
    [Display(Name = "物料类型", Description = "物料类型：备品备件、化工小料、大宗原材料", GroupName = "采购类型")]
    public MaterialType? MaterialType { get; set; }

    #endregion

    #region 紧急和优先级

    /// <summary>
    /// 获取或设置紧急程度
    /// </summary>
    /// <value>采购的紧急程度：一般、紧急</value>
    [Display(Name = "紧急程度", Description = "采购的紧急程度：一般、紧急", GroupName = "紧急信息")]
    public UrgencyLevel? UrgencyLevel { get; set; }

    #endregion

    #region 时间信息

    /// <summary>
    /// 获取或设置要求到货日期
    /// </summary>
    /// <value>要求的到货日期</value>
    [Required(ErrorMessage = "要求到货日期不能为空")]
    [Display(Name = "要求到货日期", Description = "要求的到货日期", GroupName = "时间信息")]
    public DateTime? RequiredDeliveryDate { get; set; }

    /// <summary>
    /// 获取或设置审批通过日期
    /// </summary>
    /// <value>申请单最终审批通过的日期</value>
    [Required(ErrorMessage = "审批通过日期不能为空")]
    [Display(Name = "审批通过日期", Description = "申请单最终审批通过的日期", GroupName = "时间信息")]
    public DateTime? ApprovalDate { get; set; }

    /// <summary>
    /// 获取或设置入池日期
    /// </summary>
    /// <value>需求进入需求池的日期</value>
    [Required(ErrorMessage = "入池日期不能为空")]
    [Display(Name = "入池日期", Description = "需求进入需求池的日期", GroupName = "时间信息")]
    public DateTime? EntryDate { get; set; }

    #endregion

    #region 采购状态

    /// <summary>
    /// 获取或设置采购状态
    /// </summary>
    /// <value>采购状态：待采购、部分采购、已采购</value>
    [Required(ErrorMessage = "采购状态不能为空")]
    [Display(Name = "采购状态", Description = "采购状态：待采购、部分采购、已采购", GroupName = "采购状态")]
    public PurchaseState? PurchaseState { get; set; }

    /// <summary>
    /// 获取或设置采购策略
    /// </summary>
    /// <value>采购策略：询比价、招投标、协议采购</value>
    [Display(Name = "采购策略", Description = "采购策略：询比价、招投标、协议采购", GroupName = "采购状态")]
    public PurchaseStrategy? PurchaseStrategy { get; set; }

    #endregion
}

/// <summary>
/// 采购状态枚举
/// </summary>
/// <remarks>
/// 定义需求池明细的采购执行状态
/// </remarks>
public enum PurchaseState
{
    /// <summary>
    /// 待立项：需求尚未开始立项
    /// </summary>
    [Display(Name = "待立项")]
    待立项 = 10,
    
    立项中 = 15,
    
    已立项 = 20,
    
    已取消 = 40,
}

/// <summary>
/// 采购策略枚举
/// </summary>
/// <remarks>
/// 定义不同的采购执行策略
/// </remarks>
public enum PurchaseStrategy
{
    /// <summary>
    /// 询比价：通过询价比价方式选择供应商
    /// </summary>
    [Display(Name = "询比价")]
    询比价 = 10,

    /// <summary>
    /// 招投标：通过正式招标流程选择供应商
    /// </summary>
    [Display(Name = "招投标")]
    招投标 = 20,

    /// <summary>
    /// 协议采购：通过现有框架协议直接采购
    /// </summary>
    [Display(Name = "协议采购")]
    协议采购 = 30
}

